import { useLocation } from "react-router-dom";
import { searchRoute } from "@/utils/index";
import { allRouter } from "@/router/index";
import { JSX } from "react";

/**
 * @description 路由守卫组件
 * */
const AuthRouter = (props: { children: JSX.Element }) => {
    const { pathname } = useLocation();
    const route = searchRoute(pathname, allRouter);
    // console.log(route, "pppppppppppp")


    // * 未登录返回登录页
    // const token = true;
    // if (!token && route.path !== "/login") {
    //     console.log('111111111111')
    //     return <Navigate to="/login" replace />;
    // }

    // * 判断当前路由是否需要访问权限(不需要权限直接放行)
    if (!route.meta?.requiresAuth) return props.children;








    return props.children;
};

export default AuthRouter;
